<template>
  <j-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    switchFullscreen
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">

        <a-form-item label="上架任务ID" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['upshelfTaskid']" placeholder="请输入上架任务ID"></a-input>
        </a-form-item>
        <a-form-item label="上架任务行号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['upshelfRownum']" placeholder="请输入上架任务行号"></a-input>
        </a-form-item>
        <a-form-item label="状态" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['state']" placeholder="请输入状态"></a-input>
        </a-form-item>
        <a-form-item label="基本行号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['baseRownum']" placeholder="请输入基本行号"></a-input>
        </a-form-item>
        <a-form-item label="基本单号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['baseCode']" placeholder="请输入基本单号"></a-input>
        </a-form-item>
        <a-form-item label="基本单据类型" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['baseDockettype']" placeholder="请输入基本单据类型"></a-input>
        </a-form-item>
        <a-form-item label="产品编号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['productCode']" placeholder="请输入产品编号"></a-input>
        </a-form-item>
        <a-form-item label="产品名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['productName']" placeholder="请输入产品名称"></a-input>
        </a-form-item>
        <a-form-item label="仓库编号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['wareCode']" placeholder="请输入仓库编号"></a-input>
        </a-form-item>
        <a-form-item label="货主编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['shipperCode']" placeholder="请输入货主编码"></a-input>
        </a-form-item>
        <a-form-item label="批次号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['wholeNum']" placeholder="请输入批次号"></a-input>
        </a-form-item>
        <a-form-item label="源库位编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['resourceSitecode']" placeholder="请输入源库位编码"></a-input>
        </a-form-item>
        <a-form-item label="源跟踪号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['resourceNum']" placeholder="请输入源跟踪号"></a-input>
        </a-form-item>
        <a-form-item label="目标跟踪号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['targetNum']" placeholder="请输入目标跟踪号"></a-input>
        </a-form-item>
        <a-form-item label="推荐库位" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['recommendWaresite']" placeholder="请输入推荐库位"></a-input>
        </a-form-item>
        <a-form-item label="包装编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['parcelCode']" placeholder="请输入包装编码"></a-input>
        </a-form-item>
        <a-form-item label="包装单位" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['parcelUnit']" placeholder="请输入包装单位"></a-input>
        </a-form-item>
        <a-form-item label="上架包装数量" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['upshelfParcelnum']" placeholder="请输入上架包装数量"></a-input>
        </a-form-item>
        <a-form-item label="上架数量" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['upshelfNum']" placeholder="请输入上架数量"></a-input>
        </a-form-item>
        <a-form-item label="上架操作人" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['upshelfOperator']" placeholder="请输入上架操作人"></a-input>
        </a-form-item>
        <a-form-item label="上架时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="请选择上架时间" v-decorator="['upshelfTime']" :trigger-change="true" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="打印次数" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['printNum']" placeholder="请输入打印次数"></a-input>
        </a-form-item>
        <a-form-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-textarea v-decorator="['notes']" rows="4" placeholder="请输入备注"/>
        </a-form-item>

      </a-form>
    </a-spin>
  </j-modal>
</template>

<script>

  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import { validateDuplicateValue } from '@/utils/util'
  import JDate from '@/components/jeecg/JDate'  


  export default {
    name: "MesStorageShelftaskModal",
    components: { 
      JDate,
    },
    data () {
      return {
        form: this.$form.createForm(this),
        title:"操作",
        width:800,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/storage/mesStorageShelftask/add",
          edit: "/storage/mesStorageShelftask/edit",
        }
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'upshelfTaskid','upshelfRownum','state','baseRownum','baseCode','baseDockettype','productCode','productName','wareCode','shipperCode','wholeNum','resourceSitecode','resourceNum','targetNum','recommendWaresite','parcelCode','parcelUnit','upshelfParcelnum','upshelfNum','upshelfOperator','upshelfTime','printNum','notes'))
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            console.log("表单提交数据",formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }
         
        })
      },
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'upshelfTaskid','upshelfRownum','state','baseRownum','baseCode','baseDockettype','productCode','productName','wareCode','shipperCode','wholeNum','resourceSitecode','resourceNum','targetNum','recommendWaresite','parcelCode','parcelUnit','upshelfParcelnum','upshelfNum','upshelfOperator','upshelfTime','printNum','notes'))
      },

      
    }
  }
</script>